import { http } from '@pier88health/p8h-common'
import axios from 'axios'
import DBConfig from '@CONFIG/DBConfig'
import Storage, { StorageKey } from '@UTILS/Storage'

const { fetchRequest } = http
const getToken = async () => {
  const token = await Storage.get(StorageKey.token)
  return token
}
http.init({
  baseUrl: `${DBConfig.baseUrl}/vio`,
  axios,
  logEnable: true,
  enableCacheToken: true,
  errorKey: 'error',
  getToken,
})
const Api = {
  requestAuthCode: fetchRequest('/User/RequestAuthCode', 'POST'),
  loginByPhone: fetchRequest('/User/LoginOrRegisterByPhone', 'POST'),
  logout: fetchRequest('/User/Logout', 'POST'),
  forbidUser: fetchRequest('/User/ForbidUser', 'POST'),
  checkStatus: fetchRequest('/PubClient/CheckStatus', 'GET'),
  deviceRegister: fetchRequest('/Device/Register', 'POST'),
  devicePair: fetchRequest('/Device/Pair', 'POST'),
  addActivity: fetchRequest('/Device/AddActivity', 'POST'),
}

export default Api
